<?php
namespace Admin\Controller;
use Think\Controller;
class SingleController extends AdminController {
    public function about(){
        if(IS_POST){
            $data = I('post.');
            $data['info'] = I('post.info','','clear_js');
            $data['c_time']=$data['u_time'] = time();
            $res = M('About')->data($data)->add();
            if($res){
                $this->success('设置成功',U('about'));
            }else{
                $this->error('设置失败');
            }
        }else{
            $one = M('about')->order('u_time desc')->find();

            $this->assign('one',$one);
            $this->display();
        }
    }

    public function upload_img($type=0)
    {
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize = 2 * 1024 * 1024 ;// 设置附件上传大小 2m
        $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath = './Uploads/'; // 设置附件上传根目录
        // $upload->savePath = 'Goods/'; // 设置附件上传（子）目录
        $upload->subName = array('date','Y/m/d');
        // 上传文件
        $info = $upload->uploadOne($_FILES['file']);
//        dump($info);
//        exit;
        if(!$info) { // 上传错误提示错误信息
            $this->ajaxReturn(array("error"=>$upload->getError()));

        }else{ // 上传成功
            $pic_url = 'Uploads/'.$info['savepath'].$info['savename'];
            $image = new \Think\Image();
            $img = $image->open($pic_url);
            // $img1 = clone($img);
//            exit;

            $water = M('Water')->find();
//          $thumb = get_thumb($pic_url);//_thumb

            /*  //缩小 图片
                //生成一个缩放后填充大小150*150的缩略图并保存为thumb.jpg
                $image->open($water['mark_img']);
                $image->thumb(150, 150,\Think\Image::IMAGE_THUMB_FILLED)->save('./thumb.jpg');*/

            $waterImgUrl = strstr($water['mark_img'],'Uploads');
            if(!$type){
                $img->thumb(555,350,3)->save($pic_url);
//                $img->thumb(555, 350,3)->water($waterImgUrl,$water['mark_pos'],$water['alpha'])->save($pic_url);
            }else{
                $img->thumb(490, 490,3)->ater($waterImgUrl,$water['mark_pos'],$water['alpha'])->save($pic_url);
            }
            // $img->thumb(400, 800,3)->water($water['mark_img'])->save($thumb);
            // $img1->water($water['mark_img'])->save($pic_url);
            $this->ajaxReturn(array('error'=>'0','pic'=>__ROOT__.'/'.$pic_url,'name'=>$info['savename']));
        }
    }


}
?>